﻿using Signalrs.context;
using BasicModuleWebApiJWTAuthorization.Model;
using Microsoft.EntityFrameworkCore;
using EFCore.BulkExtensions;

namespace Signalrs.Repositories
{
    public class UserRepository : IUserRepository
    {
        public AppDbContext _dbContext;

        public UserRepository(AppDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task<User?> GetByIdAsync(int id)
        {
            return await _dbContext.Users.FindAsync(id);
        }

        public async Task AddAsync(User user)
        {
            await _dbContext.BulkInsertAsync<User>(new List<User>() { user });
            await _dbContext.Users.AddAsync(user);
            await _dbContext.SaveChangesAsync();
        }

        public async Task<List<User>> GetAllAsync()
        {
            return await _dbContext.Users.ToListAsync();
        }
    }
}
